#include "motor.h"

void Motor_start(void)
{
	HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_1);
}


void Motor_stop(char Motor)
{
	switch (Motor)
	{
		case 'A':
			GPIOB->ODR &= 0xFC;
		break;
		case 'B':
			GPIOB->ODR &= 0xF3;
		break;
		default:
			GPIOB->ODR = 0x00;
		break;
	}	
}

void Motor_A_Z(void)
{
	GPIOB->ODR &= 0xFC;
	GPIOB->ODR |= 0x01;
}

void Motor_B_Z(void)
{
	GPIOB->ODR &= 0xF3;
	GPIOB->ODR |= 0x04;
}

void Motor_A_F(void)
{
	GPIOB->ODR &= 0xFC;
	GPIOB->ODR |= 0x02;
}

void Motor_B_F(void)
{
	GPIOB->ODR &= 0xF3;
	GPIOB->ODR |= 0x08;
}

int Motor_Set_Speed(uint16_t speed)
{
	if(speed >= 1000) return 0;
	
	TIM4->CCR1 = speed;
	return 1;
}
